
<?php
/*
 *  This file is part of Urd.
 *
 *  Urd is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *  Urd is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program. See the file "COPYING". If it does not
 *  exist, see <http://www.gnu.org/licenses/>.
 *
 * $LastChangedDate: 2008-06-29 19:51:21 +0200 (Sun, 29 Jun 2008) $
 * $Rev: 1238 $
 * $Author: gavinspearhead $
 * $Id: admin_tasks.php 1238 2008-06-29 17:51:21Z gavinspearhead $
 */
define('ORIGINAL_PAGE', $_SERVER['PHP_SELF']);


$pathadt = realpath(dirname(__FILE__));

require_once "$pathadt/../functions/ajax_includes.php";

$dlpath = get_dlpath($db);

$postid = get_request('postid', NULL);

$dir = POST_PATH . $username;
$readonly = FALSE;

$dirs = glob($dlpath . $dir . '/*', GLOB_ONLYDIR);
if ($dirs == array()) 
    throw new exception("No directories found"); 
if ($postid === NULL || !is_numeric($postid)) {
    $poster_email = $prefs['poster_email'];
    $poster_name = $prefs['poster_name'];
    $recovery_size = $prefs['recovery_size'];
    $rarfile_size = $prefs['rarfile_size'];
    $delete_files = 0;
    $subject = '';
    $group = '';
    $dir = '';
    $postid = '';
    $start_time = '';
} else {
    $dbpostid = $postid;
    $db->escape($dbpostid, TRUE);
    $db->escape($userID, TRUE);
    $sql = "SELECT * FROM postinfo WHERE \"id\" = $dbpostid";
    if (!$isadmin)
        $sql .= " AND \"userid\" = $userID";
        
    $res = $db->execute_query($sql);
    if ($res == FALSE)
        throw new exception ($LN['error_post_not_found'] . ": $postid", ERR_POST_NOT_FOUND);
    $row = $res[0];
    $group = $row['groupid'];
    $subject = $row['subject'];
    $poster_email = $row['poster_id'];
    $poster_name = $row['poster_name'];
    $rarfile_size = $row['filesize_rar'];
    $recovery_size = $row['recovery_par'];
    $delete_files = $row['delete_files'];
    $start_time = get_smart_timestamp( $row['start_time']);
    $status = $row['status'];
    $dir = $row['src_dir'];
    if ($status != POST_READY)
        $readonly = TRUE;
}

$groupinfo = get_all_active_groups($db);
foreach($groupinfo as $gr) 
    $groups[$gr['ID']] = $gr['name'];

natsort($groups);

$challenge = set_challenge();
$smarty->assign('challenge',    	$challenge);
$smarty->assign('postid',      	    $postid);
$smarty->assign('groups',    	    $groups);
$smarty->assign('group',    	    $group);
$smarty->assign('dirs',    	        $dirs);
$smarty->assign('readonly',         $readonly?1:0);
$smarty->assign('dir',    	        $dir);
$smarty->assign('subject',    	    $subject);
$smarty->assign('start_time',    	$start_time);
$smarty->assign('poster_name',    	$poster_name);
$smarty->assign('delete_files',    	$delete_files);
$smarty->assign('poster_email',    	$poster_email);
$smarty->assign('rarfile_size',    	$rarfile_size);
$smarty->assign('recovery_size',   	$recovery_size);


$smarty->display('ajax_show_post.tpl');

?>
